// volume_param.cpp : Defines the entry point for the console application.
//

#include "Mesh.h"
#include "FnVolumeHarmonicParam.h"
#include <OpenVolMesh/Core/IO/MeshIO.hh>
#include "./CmdLine/CmdLine.h"


int main(int argc, char* argv[])
{
  CCmdLine                  cmdLine;
  std::string               in_filename, out_filename, embed_filename;
  WeightType                weight_type = kUniform;

  if (cmdLine.SplitLine(argc, argv) < 1)
  {
     // no switches were given on the command line, abort
     assert(0);
     exit(-1);
  }

   /// check the required options
  if (!cmdLine.HasSwitch("-in") ||
      !cmdLine.HasSwitch("-out"))      
  {
    std::cerr << "Usage: volume_param -in <input_mesh> -out <output_mesh> ..." << std::endl;
    return  0;
  }
  // read I/O options
  in_filename = cmdLine.GetArgument("-in", 0);
  out_filename = cmdLine.GetArgument("-out", 0);


  Mesh                      mesh;
  OpenVolMesh::IO::Options  opt;

  if (cmdLine.HasSwitch("-weight_type"))
  {
    std::string   weight_type_name; 
    
    weight_type_name = cmdLine.GetArgument("-weight_type", 0);
    std::cout << weight_type_name  << std::endl;

    if (weight_type_name == "uniform")            
      weight_type = kUniform;
    else if (weight_type_name == "cotangent" || weight_type_name == "cotan")
      weight_type = kCotangent;    
  }


  // loading an input mesh
  OpenVolMesh::IO::read_mesh(mesh, in_filename.c_str(), opt);

  std::cout << "computing harmonic volume parameterization" << std::endl;  


  FnVolumeHarmonicParam   fnParam(mesh);


  fnParam.debug_save_boundary("ttt.obj");

  fnParam.set_weight_type(weight_type);
  fnParam.read_face_side_info(in_filename);
  
  fnParam.print_info();
  
  fnParam.init();  
  fnParam.calc();
  fnParam.debug_output_params();
  fnParam.debug_param_flipping_test();
  fnParam.save(out_filename);


	return 0;
}

